package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.OverFlowDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author nzmxfan
 * @create 2021-09-05-0:45
 */
@Service
public class OverFlowServiceImpl implements OverFlowService {

    @Autowired
    OverFlowDao overFlowDao;

    @Override
    public void saveOverFlow(OverflowList overflowList, String overflowListGoodsStr) {
        // overflowListGoodsStr 为 overflowList 对象的 json 字符串

        // 设置时间
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = format.format(new Date());
        overflowList.setOverflowDate(dateStr);
        overFlowDao.saveOverFlow(overflowList);
    }

    @Override
    public Map<String, Object> getDamageList(String sTime, String eTime) {

        Map<String, Object> map = new HashMap<>();
        List<OverflowList> overflowLists = overFlowDao.getDamageList(sTime, eTime);
        map.put("rows", overflowLists);
        return map;
    }

    @Override
    public Map<String, Object> goodsList(Integer overflowListId) {

        Map<String, Object> map = new HashMap<>();
        List<OverflowListGoods> overflowListGoods = overFlowDao.goodsList(overflowListId);
        map.put("rows", overflowListGoods);
        return map;
    }
}
